Skip to content

fix(compostition): Fix port of @composeDirective#9164

Merged
sachindshinde merged 4 commits intodevfrom
sachin/fix-compose-directive
Apr 13, 2026
Merged

fix(compostition): Fix port of @composeDirective#9164
sachindshinde merged 4 commits intodevfrom
sachin/fix-compose-directive

Conversation

@sachindshinde
Copy link
Copy Markdown
Contributor

@sachindshinde sachindshinde commented Apr 9, 2026

While reviewing #8936, I noticed some issues in the PR, but there were also more issues in the surrounding code for @composeDirective. This PR brings the Rust port more inline with the JS code (including the changes that #8936 were trying to port over). There were also a fair amount of issues with the tests, and I've similarly fixed those.

@sachindshinde sachindshinde requested a review from a team as a code owner April 9, 2026 20:06
@apollo-librarian
Copy link
Copy Markdown
Contributor

apollo-librarian bot commented Apr 9, 2026

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: 934c34d39b08f82bcc092113
Build Logs: View logs


✅ AI Style Review — No Changes Detected

No MDX files were changed in this pull request.

Review Log: View detailed log

This review is AI-generated. Please use common sense when accepting these suggestions, as they may not always be accurate or appropriate for your specific context.

@sachindshinde sachindshinde force-pushed the sachin/fix-compose-directive branch from 5a5c008 to be72cb3 Compare April 9, 2026 20:07
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

@sachindshinde, please consider creating a changeset entry in /.changesets/. These instructions describe the process and tooling.

Copy link
Copy Markdown
Member

@dariuszkuc dariuszkuc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good just a couple questions around tests

);

let result = compose(vec![subgraph_a, subgraph_b]).unwrap();
println!("{:?}", result.hints());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover from debugging?

pub spec_alias: Option<Name>,
pub imports: Vec<Arc<Import>>,
pub purpose: Option<Purpose>,
pub line_column_range: Option<Range<LineColumn>>,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note for self: this is added so we can calculate location information for subgraph errors

let imports = directives
.iter()
.map(|(original, alias)| {
.map(|(alias, original)| {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

Comment thread apollo-federation/src/merger/merger.rs Outdated
@@ -1687,18 +1684,14 @@ format!("Field \"{field}\" of {} type \"{}\" is defined in some but not all subg
// We should skip the supergraph specific directives, that is the @core and @join directives.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you update this comment to @link and @join directives?

);
let subgraph_b = generate_subgraph(
"subgraphB",
r#"@link(url: "https://specs.custom.dev/foo/v1.1", import: ["@bar"])"#,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wondering whether we should be explicit with import: ["@bar", "@foo"] here (or maybe use different custom directive names as @foo is implicitly handled as its name matches the spec name)

r#"@composeDirective(name: "@foo")"#,
r#"
directive @foo(name: String!) on FIELD_DEFINITION
directive @bar(name: String!) on FIELD_DEFINITION
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this only include @foo definition and skip the @bar (and vice versa in subgraph_b)?

r#"@composeDirective(name: "@foo")"#,
r#"
directive @foo(name: String!) on FIELD_DEFINITION
directive @bar(name: String!) on FIELD_DEFINITION
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop the @bar

Comment thread apollo-federation/tests/composition/compose_directive.rs Outdated
@sachindshinde sachindshinde force-pushed the sachin/fix-compose-directive branch from b809f3d to ac63648 Compare April 13, 2026 20:38
@sachindshinde
Copy link
Copy Markdown
Contributor Author

@dariuszkuc
Finished auditing the tests (both the existing ones, and the new ones). There were a fair amount of issues there too, I ended up comparing side-by-side with the JS and what's been pushed up should be matching now (there's one or two cases where I think in the Rust tests we decided some JS tests subsumed each other/were too similar so we didn't port them; from what I could see those cases were fine to not port).

directive_text,
r#"
directive @foo(name: String!) on FIELD_DEFINITION
directive @bar(name: String!, address: String) on FIELD_DEFINITION | OBJECT
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need the bar in 1.0 subgraph?

Copy link
Copy Markdown
Contributor Author

@sachindshinde sachindshinde Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, it's just copied over from the JS tests (it's named "exported directive not imported everywhere. named consistently" in JS tests). The definition shouldn't be affecting/testing anything.

@sachindshinde sachindshinde force-pushed the sachin/fix-compose-directive branch from 09f7e0f to ea5f114 Compare April 13, 2026 21:50
@sachindshinde sachindshinde enabled auto-merge (squash) April 13, 2026 21:51
@sachindshinde sachindshinde merged commit 310d7b5 into dev Apr 13, 2026
18 checks passed
@sachindshinde sachindshinde deleted the sachin/fix-compose-directive branch April 13, 2026 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants